package com.ngo.exception;

import com.ngo.constant.Response;
import com.ngo.model.vo.ResponseVO;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;


@ControllerAdvice
public class GlobalExceptionHandler {

	private static final Logger log = LoggerFactory
			.getLogger(GlobalExceptionHandler.class);

	@ExceptionHandler(Exception.class)
	@ResponseBody
	public ResponseVO<Object> defaultErrorHandler(Exception ex)
			throws Exception {
		log.error("***系统错误***", ex);
		StringBuilder sb = new StringBuilder("系统异常:");
		sb.append(StringUtils.substring(ex.getMessage(), 0, 100));
		return ResponseVO.error(Response.FAILURE.getState(), sb.toString());
	}

}
